<template>
  <div class="container">
    <div class="nav">
      <div class="top">
        <router-link to="my">
          <i></i>
        </router-link>

        <h5>我的订单</h5>

        <span></span>
      </div>

      <div class="choose">
        <van-tabs v-model="activeName">
          <!-- <van-tab
            :title="item.title"
            v-for="(item, index) in myorder"
            :key="index"
          > -->

          <van-tab title="全部" name="a">
            <div class="main">
              <div
                class="box"
                v-for="(item, index) in allorder"
                :key="index"
                v-show="!showhave"
              >
                <!-- 顶部时间提示 -->
                <div class="top">
                  <h6>{{ item.time }}</h6>
                  <h5 v-if="item.type == '1'">待付款</h5>
                  <h5 v-if="item.type == '2'">待发货</h5>
                  <h5 v-if="item.type == '3'">已收货</h5>
                  <h5 v-if="item.type == '4'">已评价</h5>
                </div>
                <!-- 书本信息 -->
                <div v-for="(item2, index) in item.lists" :key="index">
                  <!-- 书本信息 -->
                  <div class="content">
                    <!-- 书本图片 -->
                    <div class="left">
                      <img :src="item2.bannerData.img" alt="" />
                    </div>
                    <!-- 右边信息 -->
                    <div class="right">
                      <h6>{{ item2.bannerData.title }}</h6>

                      <span>x{{ item2.bannerData.num }}</span>

                      <div class="text">
                        ￥{{ item2.bannerData.disprice
                        }}<s>￥{{ item2.bannerData.price }}</s>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- 底部确认信息 -->
                <div class="bottom">
                  <!-- 价格 -->
                  <div class="navtop">
                    <h6>快递:0.00</h6>
                    <h5>合计:￥{{ item.total }}</h5>
                  </div>
                  <!-- 删除订单 -->
                  <div class="navbottom">
                    <div class="del2">
                      <van-cell is-link @click="showPopup(item.id)"
                        >删除订单</van-cell
                      >
                      <!-- 只显示我点击的 -->
                      <van-popup v-model:show="show" v-if="gonum == item.id">
                        <div class="inside2">
                          <h5>取消订单提示</h5>
                          <h6>是否删除订单</h6>
                          <div class="choose">
                            <div class="left" @click="test">取消</div>
                            <div class="right" @click="yesdel(item.id)">
                              确定
                            </div>
                          </div>
                        </div>
                      </van-popup>
                    </div>

                    <div class="del" v-if="item.type != '4'"  >
                      <van-cell
                        is-link
                        @click="showPopup2(item.id)"
                        v-if="item.type == '1'"
                        >确认付款</van-cell
                      >
                      <van-cell
                        is-link
                        @click="showPopup2(item.id)"
                        v-if="item.type == '2'"
                        >确认收货</van-cell
                      >
                      <van-cell
                        is-link
                        @click="changetype(item.type)"
                        v-if="item.type == '3'"
                        >待评价</van-cell
                      >
                      
                      <van-popup v-model:show="show2" v-if="gonum == item.id">
                        <div class="inside2">
                          <h5 v-if="item.type == '1'">确认付款提示</h5>
                          <h6 v-if="item.type == '1'">是否确认付款</h6>
                          <h5 v-if="item.type == '2'">确认收货提示</h5>
                          <h6 v-if="item.type == '2'">是否确认收货</h6>
                          <div class="choose">
                            <div class="left" @click="test">取消</div>
                            <div class="right" @click="changetype(item.type)">
                              确定
                            </div>
                          </div>
                        </div>
                      </van-popup>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <!-- 暂无订单信息 -->
            <div class="logo" v-show="showhave">
              <img src="../assets/img/ic_empty_order.0969e59.png" alt="" />

              <h5>暂无订单信息哦</h5>
            </div>
          </van-tab>

          <van-tab title="待付款" name="b">
            <div class="main">
              <div
                class="box"
                v-for="(item, index) in mabytopay"
                :key="index"
                v-show="youlook"
              >
                <!-- 顶部时间提示 -->
                <div class="top">
                  <h6>{{ item.time }}</h6>
                  <h5 v-if="item.type == '1'">待付款</h5>
                  <h5 v-if="item.type == '2'">待发货</h5>
                  <h5 v-if="item.type == '3'">已收货</h5>
                </div>
                <div v-for="(item2, index) in item.lists" :key="index">
                  <!-- 书本信息 -->
                  <div class="content">
                    <!-- 书本图片 -->
                    <div class="left">
                      <img :src="item2.bannerData.img" alt="" />
                    </div>
                    <!-- 右边信息 -->
                    <div class="right">
                      <h6>{{ item2.bannerData.title }}</h6>

                      <span>x{{ item2.bannerData.num }}</span>

                      <div class="text">
                        ￥{{ item2.bannerData.disprice
                        }}<s>￥{{ item2.bannerData.price }}</s>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- 底部确认信息 -->
                <div class="bottom">
                  <div class="navtop">
                    <h6>快递:0.00</h6>
                    <h5>合计:￥{{ item.total }}</h5>
                  </div>

                  <div class="navbottom">
                    <div class="del2">
                      <van-cell is-link @click="showPopup(item.id)"
                        >删除订单</van-cell
                      >
                      <!-- 只显示我点击的 -->
                      <van-popup v-model:show="show" v-if="gonum == item.id">
                        <div class="inside2">
                          <h5>取消订单提示</h5>
                          <h6>是否删除订单</h6>
                          <div class="choose">
                            <div class="left" @click="test">取消</div>
                            <div class="right" @click="yesdel(item.id)">
                              确定
                            </div>
                          </div>
                        </div>
                      </van-popup>
                    </div>

                    <div class="del" v-if="item.type != '3'">
                      <van-cell
                        is-link
                        @click="showPopup2(item.id)"
                        v-if="item.type == '1'"
                        >确认付款</van-cell
                      >
                      <van-cell
                        is-link
                        @click="showPopup2(item.id)"
                        v-if="item.type == '2'"
                        >确认收货</van-cell
                      >
                      <van-popup v-model:show="show2" v-if="gonum == item.id">
                        <div class="inside2">
                          <h5 v-if="item.type == '1'">确认付款提示</h5>
                          <h6 v-if="item.type == '1'">是否确认付款</h6>
                          <h5 v-if="item.type == '2'">确认收货提示</h5>
                          <h6 v-if="item.type == '2'">是否确认收货</h6>
                          <div class="choose">
                            <div class="left" @click="test">取消</div>
                            <div class="right" @click="changetype(item.type)">
                              确定
                            </div>
                          </div>
                        </div>
                      </van-popup>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <!-- 暂无订单信息 -->
            <div class="logo" v-show="!youlook">
              <img src="../assets/img/ic_empty_order.0969e59.png" alt="" />

              <h5>暂无订单信息哦</h5>
            </div>
          </van-tab>
          <van-tab title="待发货" name="c">
            <div class="main">
              <div
                class="box"
                v-for="(item, index) in readytopay"
                :key="index"
                v-show="theylook"
              >
                <!-- 顶部时间提示 -->
                <div class="top">
                  <h6>{{ item.time }}</h6>
                  <h5 v-if="item.type == '1'">待付款</h5>
                  <h5 v-if="item.type == '2'">待发货</h5>
                  <h5 v-if="item.type == '3'">已收货</h5>
                </div>
                <div v-for="(item2, index) in item.lists" :key="index">
                  <!-- 书本信息 -->
                  <div class="content">
                    <!-- 书本图片 -->
                    <div class="left">
                      <img :src="item2.bannerData.img" alt="" />
                    </div>
                    <!-- 右边信息 -->
                    <div class="right">
                      <h6>{{ item2.bannerData.title }}</h6>

                      <span>x{{ item2.bannerData.num }}</span>

                      <div class="text">
                        ￥{{ item2.bannerData.disprice
                        }}<s>￥{{ item2.bannerData.price }}</s>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- 底部确认信息 -->
                <div class="bottom">
                  <div class="navtop">
                    <h6>快递:0.00</h6>
                    <h5>合计:￥{{ item.total }}</h5>
                  </div>

                  <div class="navbottom">
                    <div class="del2">
                      <van-cell is-link @click="showPopup(item.id)"
                        >删除订单</van-cell
                      >
                      <!-- 只显示我点击的 -->
                      <van-popup v-model:show="show" v-if="gonum == item.id">
                        <div class="inside2">
                          <h5>取消订单提示</h5>
                          <h6>是否删除订单</h6>
                          <div class="choose">
                            <div class="left" @click="test">取消</div>
                            <div class="right" @click="yesdel(item.id)">
                              确定
                            </div>
                          </div>
                        </div>


                      </van-popup>
                    </div>

                    <div class="del" v-if="item.type != '3'">
                      <van-cell
                        is-link
                        @click="showPopup2(item.id)"
                        v-if="item.type == '1'"
                        >确认付款</van-cell
                      >
                      <van-cell
                        is-link
                        @click="showPopup2(item.id)"
                        v-if="item.type == '2'"
                        >确认收货</van-cell
                      >
                      <van-popup v-model:show="show2" v-if="gonum == item.id">
                        <div class="inside2">
                          <h5 v-if="item.type == '1'">确认付款提示</h5>
                          <h6 v-if="item.type == '1'">是否确认付款</h6>
                          <h5 v-if="item.type == '2'">确认收货提示</h5>
                          <h6 v-if="item.type == '2'">是否确认收货</h6>
                          <div class="choose">
                            <div class="left" @click="test">取消</div>
                            <div class="right" @click="changetype(item.type)">
                              确定
                            </div>
                          </div>
                        </div>
                      </van-popup>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <!-- 暂无订单信息 -->
            <div class="logo" v-show="!theylook">
              <img src="../assets/img/ic_empty_order.0969e59.png" alt="" />

              <h5>暂无订单信息哦</h5>
            </div>
          </van-tab>
          <van-tab title="待收货" name="d">
            <div class="logo" v-show="true">
              <img src="../assets/img/ic_empty_order.0969e59.png" alt="" />

              <h5>暂无订单信息哦</h5>
            </div>
          </van-tab>
          <van-tab title="待评价" name="e">
           <div class="main">
              <div
                class="box"
                v-for="(item, index) in talkabout"
                :key="index"
                v-show="ourlook"
              >
                <!-- 顶部时间提示 -->
                <div class="top">
                  <h6>{{ item.time }}</h6>
                  <h5 v-if="item.type == '1'">待付款</h5>
                  <h5 v-if="item.type == '2'">待发货</h5>
                  <h5 v-if="item.type == '3'">已收货</h5>
                  <h5 v-if="item.type == '4'">已评价</h5>
                </div>
                <!-- 书本信息 -->
                <div v-for="(item2, index) in item.lists" :key="index">
                  <!-- 书本信息 -->
                  <div class="content">
                    <!-- 书本图片 -->
                    <div class="left">
                      <img :src="item2.bannerData.img" alt="" />
                    </div>
                    <!-- 右边信息 -->
                    <div class="right">
                      <h6>{{ item2.bannerData.title }}</h6>

                      <span>x{{ item2.bannerData.num }}</span>

                      <div class="text">
                        ￥{{ item2.bannerData.disprice
                        }}<s>￥{{ item2.bannerData.price }}</s>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- 底部确认信息 -->
                <div class="bottom">
                  <!-- 价格 -->
                  <div class="navtop">
                    <h6>快递:0.00</h6>
                    <h5>合计:￥{{ item.total }}</h5>
                  </div>
                  <!-- 删除订单 -->
                  <div class="navbottom">
                    <div class="del2">
                      <van-cell is-link @click="showPopup(item.id)"
                        >删除订单</van-cell
                      >
                      <!-- 只显示我点击的 -->
                      <van-popup v-model:show="show" v-if="gonum == item.id">
                        <div class="inside2">
                          <h5>取消订单提示</h5>
                          <h6>是否删除订单</h6>
                          <div class="choose">
                            <div class="left" @click="test">取消</div>
                            <div class="right" @click="yesdel(item.id)">
                              确定
                            </div>
                          </div>
                        </div>
                      </van-popup>
                    </div>

                    <div class="del" v-if="item.type != '4'"  >
                      <van-cell
                        is-link
                        @click="showPopup2(item.id)"
                        v-if="item.type == '1'"
                        >确认付款</van-cell
                      >
                      <van-cell
                        is-link
                        @click="showPopup2(item.id)"
                        v-if="item.type == '2'"
                        >确认收货</van-cell
                      >
                      <van-cell
                        is-link
                        @click="changetype(item.type)"
                        v-if="item.type == '3'"
                        >待评价</van-cell
                      >
                      

                    </div>
                  </div>
                </div>
              </div>
            </div>

            <!-- 暂无订单信息 -->
            <div class="logo" v-show="!ourlook">
              <img src="../assets/img/ic_empty_order.0969e59.png" alt="" />

              <h5>暂无订单信息哦</h5>
            </div>
          </van-tab>
          <van-tab title="退款" name="f">
            <div class="logo" v-show="true">
              <img src="../assets/img/ic_empty_order.0969e59.png" alt="" />

              <h5>暂无订单信息哦</h5>
            </div>
          </van-tab>
          <div class="logo" v-show="false">
            <img src="../assets/img/ic_empty_order.0969e59.png" alt="" />

            <h5>暂无订单信息哦</h5>
          </div>
        </van-tabs>
      </div>
    </div>
  </div>
</template>
<script>
import { ref } from "@vue/reactivity";
// import { Popup } from 'vant';

export default {
  setup() {
    //筛选待支付
    let mabytopay = ref("");
    //准备发货
    let readytopay = ref("");
    //待评价
    let talkabout = ref("")
    //是否展示
    let showhave = ref(false);

    //点击取消返回当前页面
    let test = () => {
      show.value = false;
      show2.value = false;
    };
    //弹出层
    const show = ref(false);
    const show2 = ref(false);

    //点击删除订单//获取点击的id
    let gonum = ref(0);
    const showPopup = (id) => {
      show.value = true;
      console.log(id);
      gonum.value = id;
    };
    //点击确认收货或确认付款时候触发
    const showPopup2 = (id) => {
      show2.value = true;
      console.log(id);
      gonum.value = id;
    };
    //获取所有订单的数据
    let allorder = ref(JSON.parse(window.localStorage.getItem("allorder")));

    if (allorder.value == null || allorder.value.length == 0) {
      showhave.value = true;
    } else {
      showhave.value = false;
    }

    const activeName = ref("a");
    //修改类型
    let changetype = (type) => {
      console.log(type);
      //查找点击的下标
      let index = allorder.value.findIndex((item) => {
        return item.type == type;
      });
      allorder.value[index].type = type + 1;
      // 存入本地
      console.log(allorder.value);
      window.localStorage.setItem("allorder", JSON.stringify(allorder.value));
      //未支付菜单
      mabytopay.value = allorder.value.filter((item) => {
        return item.type == 1;
      });
      //准备发货支付菜单
      readytopay.value = allorder.value.filter((item) => {
        return item.type == 2;
      });
      //待评价菜单
      talkabout.value = allorder.value.filter((item) => {
        return item.type == 3;
      });
      console.log(talkabout.value,111);


      if (mabytopay.value.length == 0 || mabytopay.value == null) {
        youlook.value = false;
      } else {
        youlook.value = true;
      }
      if (readytopay.value.length == 0 || readytopay.value == null) {
        theylook.value = false;
      } else {
        theylook.value = true;
      }
      if (talkabout.value.length == 0 || talkabout.value == null) {
        ourlook.value = false;
      } else {
        ourlook.value = true;
      }

      show2.value = false;
    };

    //未支付菜单
    mabytopay.value = allorder.value.filter((item) => {
      return item.type == 1;
    });
    let youlook = ref(false);
    if (mabytopay.value.length == 0 || mabytopay.value == null) {
      youlook.value = false;
    } else {
      youlook.value = true;
    }
    //准备发货支付菜单
    readytopay.value = allorder.value.filter((item) => {
      return item.type == 2;
    });
    let theylook = ref(false);
    if (readytopay.value.length == 0 || readytopay.value == null) {
      theylook.value = false;
    } else {
      theylook.value = true;
    }
    //准备发货支付菜单
    talkabout.value = allorder.value.filter((item) => {
      return item.type == 3;
    });
    let ourlook = ref(false);
    if (talkabout.value.length == 0 || talkabout.value == null) {
      ourlook.value = false;
    } else {
      ourlook.value = true;
    }

    //删除订单
    let yesdel = (id) => {
      //查找id下标
      let index = allorder.value.findIndex((item) => {
        return item.id == id;
      });
      console.log(allorder.value[index]);
      allorder.value.splice(index, 1);
      window.localStorage.setItem("allorder", JSON.stringify(allorder.value));
      show2.value = false;

      //判断是否显示
      if (mabytopay.value.length == 0 || mabytopay.value == null) {
        youlook.value = false;
      } else {
        youlook.value = true;
      }
      if (readytopay.value.length == 0 || readytopay.value == null) {
        theylook.value = false;
      } else {
        theylook.value = true;
      }
      if (talkabout.value.length == 0 || talkabout.value == null) {
        ourlook.value = false;
      } else {
        ourlook.value = true;
      }

    };

    return {
      allorder,
      activeName,
      show,
      showPopup,
      show2,
      showPopup2,
      test,
      showhave,
      youlook,
      gonum,
      changetype,
      yesdel,
      mabytopay,
      theylook,
      readytopay,
      talkabout,
      ourlook
    };
  },
};
</script>
<style lang="scss" scoped>
@import "../assets/css/base.css";
.inside2 {
  display: flex;
  flex-direction: column;
  width: 320px;
  height: 140px;
  border-radius: 3px;
  align-items: center;
  padding-top: 8px;
}
.inside2 h5 {
  font-size: 18px;
  color: #141414;
  height: 40px;
  line-height: 40px;
}
.inside2 h6 {
  color: #bebebe;
  height: 40px;
  line-height: 40px;
  margin-bottom: 14px;
}
.inside2 > .choose {
  display: flex;
  height: 43px;
  border-top: 1px solid #e3e3e3;
  align-items: center;
  width: 100%;
}
.inside2 > .choose .left {
  flex: 1;
  text-align: center;
  height: 43px;
  line-height: 43px;
  border-right: 1px solid #e3e3e3;
}
.inside2 > .choose .right {
  flex: 1;
  height: 43px;
  line-height: 43px;
  text-align: center;
  color: #2da7fb;
}

.main {
  padding: 0px 15px;
}
.main .box .bottom {
  display: flex;
  flex-direction: column;
}
.main .box .bottom .navtop h6 {
  color: #8d95a1;
  font-size: 14px;
}
.main .box .bottom .navtop {
  justify-content: space-between;
  display: flex;
  // border-bottom: 1px solid #f5f5f5;
  // height: 40px;
  align-items: center;
}
.main .box .bottom .navtop h5 {
  font-size: 14px;
}
.main .box .bottom .navbottom {
  display: flex;
  justify-content: end;
  margin-top: 10px;
}
.main .box .bottom .navbottom .del {
  height: 32px;
  line-height: 32px;
  border-radius: 18px;
  border: 1px solid #ff3233;
  // color: #ff3233;
  // font-size: 14px;
  font-weight: bold;
}
.main .box .bottom .navbottom .del2 {
  // padding: 0px 10px;
  height: 34px;
  line-height: 34px;
  border-radius: 18px;
  border: 1px solid #b7b7b7;
  color: #b7b7b7;
  // font-size: 14px;
  font-weight: bold;
  margin-right: 10px;
}
.main .box {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  // box-shadow: 0px 0px 8px 0px #c4c4c4;
}

.main .box .top {
  display: flex;
  flex: 1;
  justify-content: space-between;
  margin-top: 5px;
  border-top: 1px solid #f5f5f5;
}
.main .box .top h6 {
  // flex: 1;
  height: 50px;
  line-height: 50px;
  font-size: 14px;
  color: #969799;
}
.main .box .top h6 span {
  display: inline;
  color: #ff3233;
}
.main .box .top h5 {
  font-size: 12px;
  color: #ff3233;
  height: 40px;
  line-height: 40px;
}
.main .box .top span {
  margin: 0px;
}
.main .box .content {
  display: flex;
  flex: 1;
  height: 120px;
  // background-color: #f7f7f9;
  border-radius: 6px;
  margin-left: 6px;
  // padding-bottom: 10px;
}
.main .box .content .left {
  display: flex;
  width: 90px;
  // height: 116px;
  margin-right: 14px;
  // height: 135px;
  align-items: center;
}
.main .box .content .left img {
  width: 90px;
  // height: 116px;
}
.main .box .content .right {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: space-evenly;
}
.main .box .content .right > h6 {
  color: #2f2526;

  font-size: 14px;
  font-weight: bold;
}
.main .box .content .right span {
  color: #c1c2c4;
  font-size: 12px;
  display: block;
  height: 20px;
  line-height: 20px;
}
.main .box .content .right .text {
  color: #142b3d;
  display: flex;
  width: 100%;
  // justify-content: space-between;
  align-items: center;
}
.main .box .content .right s {
  font-size: 12px;
  color: #c2c3c7;
}
.nav {
  display: flex;
  flex-direction: column;
}
.nav .top {
  display: flex;
  margin-left: 15px;
  align-items: center;
  justify-content: space-between;
}
.nav .top i {
  background-position: 0px 11px;
  display: block;
  background-image: url(../assets/img/下载.png);
  background-repeat: no-repeat;
  width: 48px;
  height: 48px;
  background-size: 22px 22px;
}
.nav .top span {
  display: block;
  width: 48px;
  height: 48px;
}
.nav .top h5 {
  height: 48px;
  line-height: 48px;
  font-weight: bold;
  font-size: 17px;
  margin: 0px;
}

.nav .choose ul {
  display: flex;
  padding: 0px 15px 0px 15px;
  justify-content: space-between;
  height: 30px;
  line-height: 30px;
  box-shadow: 0px 7px 7px #f4f4f4;
}
.nav .choose ul li {
  font-size: 14px;
  color: #c5cacd;
  position: relative;
  height: 34px;
  line-height: 30px;
}
.nav .choose ul li.con {
  color: #242923;
  font-weight: bolder;
}
.nav .choose ul li.con::after {
  display: block;
  content: "";
  width: 22px;
  height: 4px;
  background-color: #5479fb;
  position: absolute;
  bottom: 0px;
  left: 0px;
  right: 0px;
  margin: 0px auto;
  border-radius: 2px;
}

.nav .logo {
  display: flex;
  flex-direction: column;
  margin-top: 160px;
  align-items: center;
}
.nav .logo img {
  width: 150px;
  height: 150px;
}
.nav .logo h5 {
  font-size: 15px;
  color: #9c9794;
  height: 25px;
  line-height: 25px;
}
::v-deep .van-tabs__line {
  width: 22px;
  height: 4px;
  background-color: #5479fb;
}
::v-deep .van-tabs__wrap {
  box-shadow: 0px 6px 6px 0px #eaeaea;
}
//原本颜色
::v-deep .van-tab {
  color: #c5cacd;
  font-size: 13px;
}
::v-deep .van-tabs__wrap {
  box-shadow: 0px 6px 6px 0px #eaeaea;
}

//提示窗口
::v-deep .van-tab--active {
  font-weight: bolder;
  color: #21273d;
}
::v-deep i.van-icon-arrow {
  display: none;
}
::v-deep .van-cell {
  padding: 0px 10px;
  height: 32px;
  line-height: 32px;
  border-radius: 18px;
}
.del ::v-deep .van-cell {
  padding: 0px 10px;
  height: 32px;
  line-height: 32px;
  border-radius: 18px;
}
::v-deep .van-cell__value--alone {
  color: #969799;
  font-size: 12px;
}
.del ::v-deep .van-cell__value--alone {
  color: #ff3233;
  font-size: 12px;
}
</style>